set -e

function msprof_run() {
    NAME=$1
    APP=$2
    msprof --application="${APP}" \
        --output="log/${NAME}" \
        --ascendcl=on \
        --model-execution=on \
        --runtime-api=on \
        --task-time=on \
        --hccl=on \
        --aicpu=on \
        --aic-freq=100 \
        --aic-mode=sample-based \
        --aic-metrics=PipeUtilization \
        --host-sys=cpu,mem \
        --sys-hardware-mem=on \
        --sys-hardware-mem-freq=100 \
        --sys-cpu-profiling=on \
        --sys-cpu-freq=50 \
        --sys-profiling=on \
        --sys-sampling-freq=10 \
        --sys-interconnection-profiling=on \
        --sys-interconnection-freq=50 \
        --dvpp-profiling=on \
        --dvpp-freq=100 \
        --l2=on \
        --ai-core=on
}

rm -rf log && mkdir -p log

# 编译CubeCore
cd src/cube-core && bash run.sh -r npu -v Ascend910B1 -b Release && cd -
msprof_run cube-core-1      "bash ./msprof-cube.sh 1"
# msprof_run cube-core-2      "bash ./msprof-cube.sh 2"
msprof_run cube-core-4      "bash ./msprof-cube.sh 4"
# msprof_run cube-core-8      "bash ./msprof-cube.sh 8"
# msprof_run cube-core-10     "bash ./msprof-cube.sh 10"
# msprof_run cube-core-15     "bash ./msprof-cube.sh 15"
# msprof_run cube-core-20     "bash ./msprof-cube.sh 20"
msprof_run cube-core-25     "bash ./msprof-cube.sh 25"

# # 编译VectorCore
# cd src/vector-core && bash run.sh -r npu -v Ascend910B1 -b Release && cd -
# msprof_run vector-core-1    "bash ./msprof-vector.sh 1"
# msprof_run vector-core-2    "bash ./msprof-vector.sh 2"
# msprof_run vector-core-4    "bash ./msprof-vector.sh 4"
# msprof_run vector-core-8    "bash ./msprof-vector.sh 8"
# msprof_run vector-core-10   "bash ./msprof-vector.sh 10"
# msprof_run vector-core-20   "bash ./msprof-vector.sh 20"
# msprof_run vector-core-30   "bash ./msprof-vector.sh 30"
# msprof_run vector-core-40   "bash ./msprof-vector.sh 40"
# msprof_run vector-core-50   "bash ./msprof-vector.sh 50"

# # 编译其他算子
# make
# msprof_run gemm             "python src/gemm.py"
# msprof_run hccl_allreduce   "./bin/hccl_allreduce"
